%% @doc パス設定のテスト
%%
-module(t_path).
-import(templ, [init/1,process/1,process_file/1,set_path/1,append_path/1]).

-include_lib("eunit/include/eunit.hrl").

process_file_test_() ->
	init([{"module",erlang}, 
		  {"l2a",list_to_atom}, {"l2i",list_to_integer},
		  {"string",[{"module",string}, {"substr",substr}]},
		  {"greetings","Hello {user}"}, {"user","{title} Joe"}, {"title", "Mr."},
		  {"jgreetings","こんにちは、\{juser\} 様"}, {"juser","山田太郎"}]),

	[% デフォルトはカレントディレクトリ
	 ?_assertMatch("Hello Mr. Joe !",
				   process(process(process_file("test.tmpl")))),

	 ?_assertMatch(ok,
				   append_path("../tmp")),
	 ?_assertMatch("Hello Mr. Joe !",
				   process(process(process_file("test.tmpl")))),

	 ?_assertMatch(ok,
				   set_path("../tmp")),
	 ?_assertMatch("こんにちは、山田太郎 様！",
	 			   process(process_file("test.tmpl"))),

	 ?_assertMatch(ok,
	 		   append_path(["../tmp", "../tmp/hoge"])),
	 ?_assertMatch("hogefoo", 
	 		   process(process_file("hoge.tmpl"))),

	 ?_assertMatch(ok,
				   set_path([".", "../tmp/hoge", "../tmp"])),
	 ?_assertMatch("hoge\nzero123four\n",
				   process(process(process_file("hoge.tmpl"))))
	].
